package org.phantom.securityframework.api.factory;

import java.util.List;

import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import org.phantom.securityframework.api.RealmRegister;

/**
 * spring-dm工厂
 * @author david
 *
 */
public class SpringOSGIManagerFactory implements ManagerFactory{

	/**
	 * 获取subClass对应的BundleContext，从而创建OsgiBundleXmlApplicationContext
	 */
	@SuppressWarnings("rawtypes")

	@Override
	public Object getService(Class parentClass) {
		RealmRegister register = this.getRegister();
		return register.getRealm(parentClass);
	}

	@SuppressWarnings("rawtypes")
	@Override
	public List<Object> getServices(Class parentClass) {
		RealmRegister register = this.getRegister();
		return register.getRealms(parentClass);
	}

	protected RealmRegister getRegister(){
		BundleContext context = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
		RealmRegister register = context.getService(context.getServiceReference(RealmRegister.class));
		return register;
	}

}
